package com.itheima.demo2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;

public class StreamDemo3 {
    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张无忌","周芷若","赵敏","张强","高启强","张三丰","老莫","谢逊","张无忌");

        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list,"光头强","熊出没");

        //链式编程
        list.stream()
                .filter(s -> s.startsWith("张"))
                .filter(s -> s.length()==3)
                .forEach(s-> System.out.println(s));

        //获取前面几个 limit
        list.stream().limit(3).forEach(s -> System.out.println(s));

        //跳过前面几个 skip
        list.stream().skip(4).forEach(s -> System.out.println(s));

        //跳过与获取结合
        list.stream().limit(6).skip(3).forEach(s -> System.out.println(s));

        //去重 distinct
        list.stream().distinct().forEach(s -> System.out.println(s));

        //合并 concat
        Stream.concat(list.stream(),list2.stream()).forEach(s -> System.out.println(s));


    }
}
